package cn.kgc.blogservice.controller;

import cn.kgc.blogcommon.pojo.Category;
import cn.kgc.blogcommon.pojo.News;
import cn.kgc.blogcommon.pojo.Type;
import cn.kgc.blogcommon.pojo.User;
import cn.kgc.blogservice.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
public class BlogController {
    @Autowired
    private BlogService blogService;
//    @Autowired
//    private AddressService addressService;

    @GetMapping("getAllTypes")
    public List<Type> getAllType(){
        return blogService.getAllType();
    }

    @GetMapping("getCategory")
    public List<Category> getCategory(){
        return blogService.getCategory();
    }

    @GetMapping("getAllNews")
    public List<News> getAllNews(@RequestParam("categoryId") Integer categoryId){
        List<News> newsList = blogService.getAllNews(categoryId);
        for(News n : newsList){
            System.out.println(n.getTagList().toString());
        }
        return blogService.getAllNews(categoryId);
    }

    @GetMapping("getNewsById")
    public News getNewsById(@RequestParam("newsId") Integer newsId){
        return blogService.getNewsById(newsId);
    }

    @GetMapping("getUserById")
    public User getUserById(Integer userId){
        System.out.println("blog-service服务接收usersId:" + userId);
        return blogService.getUserById(userId);
    }

    @GetMapping("getPopularCategory")
    public List<Category> getPopularCategory(){
        return blogService.getPopularCategory();
    }

    @GetMapping("getCategoryByTypeId")
    public List<Category> getCategoryByTypeId(@RequestParam("typeId") Integer typeId){
        return blogService.getCategoryByTypeId(typeId);
    }

    @GetMapping("getMinId")
    public List<Integer> getMinId(){
        return blogService.getMinId();
    }

    @GetMapping("getHotNews")
    public List<News> getHotNews(@RequestParam("newsIdList") Integer[] newsIdList){
        List<News> list = blogService.getHotNews(Arrays.asList(newsIdList));
        return blogService.getHotNews(Arrays.asList(newsIdList));
    }
}
